package com.kevin.test.spring.ioc;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

public class UserBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
	@Override
	protected void doParse(Element element, BeanDefinitionBuilder builder) {
		String userName = element.getAttribute("userName");
		String email = element.getAttribute("email");
		String id = element.getAttribute("id");
		// String group = element.getAttribute("group");
		if(StringUtils.hasText(userName)){
			builder.addPropertyValue("userName", userName);
		}
		if(StringUtils.hasText(userName)){
			builder.addPropertyValue("email", email);
		}
		if (StringUtils.hasText(id)) {
			builder.addPropertyValue("id", id);
		}
		// if (StringUtils.hasText(group)) {
		// builder.addPropertyReference("group", group);
		// }
	}
	@Override
	protected Class<?> getBeanClass(Element element) {
		return User.class;
	}

}
